<template>
  <el-container>
    <el-aside width="600px">
      <div id="myChart" :style="{width: '500px', height: '500px'}">
      </div></el-aside>
    <el-container>
      <el-main> <div id="myChart2" :style="{width: '500px', height: '500px'} " > </div></el-main>
    </el-container>
  </el-container>


</template>

<script>

import echarts from "echarts";
import axios from "axios";
import {getCounts, getHardCounts,getPaperCounts} from "@/api/store/count";
export default {
  name: 'hello',
  data () {
    return {
      msg: 'Welcome to Your Vue.js App'
    }
  },
  mounted(){
    this.drawLine();
    this.drawLine2();
  },
  methods: {
    drawLine(){
      // 基于准备好的dom，初始化echarts实例
      let myChart = echarts.init(document.getElementById('myChart'))
      // 绘制图表
      getPaperCounts({paperId:this.$route.params.paperId}).then((res)=>{
        myChart.setOption({
          title: { text: '试卷分析' },
          tooltip: {},
          legend: {
            data:['题目数量']
          },
          xAxis: {
            type: 'category',
            data: ["不及格人数","合格人数","优秀人数"]
          },
          yAxis: { type: 'value'},
          series: [{
            name: '数量',
            type: 'bar',
            showBackground: true,
            backgroundStyle: {
              color: 'rgba(180, 180, 180, 0.2)'
            },
            data: [res.data.failCounts,res.data.passCounts,res.data.fineCounts]
          }]
        });
      })
    },
    drawLine2(){
      // 基于准备好的dom，初始化echarts实例
      let myChart = echarts.init(document.getElementById('myChart2'))
      // 绘制图表
      getPaperCounts({paperId:this.$route.params.paperId}).then((res)=>{
        myChart.setOption({
          title: {
            text: '试卷分析',
            subtext: '',
            left: 'center'
          },
          tooltip: {
            trigger: 'item'
          },
          legend: {
            orient: '人数',
            left: 'left'
          },
          series: [
            {
              name: '题目数量',
              type: 'pie',
              radius: '50%',
              data: [
                { value: res.data.failCounts, name: '不合格' },
                { value: res.data.passCounts, name: '合格' },
                { value: res.data.fineCounts, name: '优秀' },
              ],
              emphasis: {
                itemStyle: {
                  shadowBlur: 10,
                  shadowOffsetX: 0,
                  shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
              }
            }
          ]
        });
      })
    },
  }
}
</script>

<style>

</style>

